<%@ page language="java" import="java.util.*,com.hs.auth.model.*,com.hs.auth.*" pageEncoding="utf-8"%>
<%
//HsAccount accInfo = (HsAccount)request.getSession().getAttribute(AUTHConstant.USERINSESSION);
//HsUserinfo userinfo = accInfo==null?null:accInfo.getUserinfo();
//String accid = String.valueOf(accInfo.getId()); 

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<%@ include file="../../include.jsp"%>   
<script language="javascript" type="text/javascript" src="<%=path %>/thirtpart/My97DatePicker/WdatePicker.js"></script>
<link rel="stylesheet" type="text/css" href="<%=basePath %>thirtpart/dhtmlx25/dhtmlxlayout.css"/>
<link rel="STYLESHEET" type="text/css" href="<%=basePath %>thirtpart/dhtmlx25/dhtmlxtree.css"/>
<link rel="stylesheet" type="text/css" href="<%=basePath %>thirtpart/dhtmlx25/skins/dhtmlxlayout_dhx_blue.css"/>
<script src="<%=basePath %>thirtpart/dhtmlx25/dhtmlxcommon.js"></script>
<script src="<%=basePath %>thirtpart/dhtmlx25/dhtmlxlayout.js"></script> 
<script src="<%=basePath %>thirtpart/dhtmlx25/dhtmlxcontainer.js"></script>  
<script  src="<%=basePath %>thirtpart/dhtmlx25/dhtmlxtree.js"></script>    
 
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
    	<td width="98%" align=left >
    	  <input   type="button" class="butto" style="margin-left:10px" onclick="resetAll();" value=" 清 除 "/>
    	  <font color=red>如需联合检索，请先勾选主题分类词。</font> 
        </td> 
    </tr> 
    <tr>
    	<td width="100%">
        	<div id="treeboxbox_tree" style="width:95%;margin-left:10px;overflow:auto;border:1px solid #bdc0c3;"></div>   
        </td> 
    </tr> 
</table>
</body>
</html> 
<script> 
var tagtype = "";
//获得所有被选中的选项
function getAllselectedId() {  
    var selectedList = tree.getAllChecked();  
    return selectedList;
    
}
//清除所有被选中的选项
function clearAllSelectedItem(){
     if(tagtype != "")
	   tree.refreshItem(tagtype);
    //tree.clearSelection();
}
function submitSearch(){ 
   window.parent.searchresult.submitSearchForm();
}
function tonclick(itemId) {
    if(itemId == 10000 || itemId==1 || itemId == 2 || itemId == 3 || itemId ==4)
       return;
       
    var checkState = tree.isItemChecked(itemId); 
    if('0' == checkState){
	    //判断是否选择了其他分类的选项
	    var userData = tree.getUserData(itemId,"tagtype");
	    if("" == tagtype){
	    	tagtype = userData;
	    }else{
	    	if(tagtype != userData){
	    	   alert("检索主题分类共分为四个主题：病名、方剂、证候、中药，同时只能选择一个主题分类！");
	    	   tree.clearSelection(itemId);
	    	   return;
	    	}
	    }
    	tree.setSubChecked(itemId,1) ;
    }
    if('1' == checkState){
    	tree.setSubChecked(itemId,0) ;
    	var allselects = getAllselectedId();
    	if("" == allselects){
    	     tagtype = "";
    	}
    	
    }
    //提交检索
    submitSearch();
};
function tondblclick(itemId) {
     
};
function toncheck(itemId) {
    if(itemId == 10000)
       return;
    var checkState = tree.isItemChecked(itemId); 
    tree.setSubChecked(itemId,checkState) ;
   //var nodelist = tree.getAllSubItems(itemId);
   //for(var i=0;i<nodelist.length;i++){
   	//	var subnode = tree.getAllSubItems(itemId);
   		
  // }
  	var allselects = getAllselectedId();
    	if("" == allselects){
    	     tagtype = "";
    	}
    //提交检索
    submitSearch();
};
function tonopen(id, mode) {
    return confirm("Do you want to " + (mode > 0 ? "close": "open") + " node " + tree.getItemText(id) + "?");
}; 

function doOnLoad() {
   //tree
tree = new dhtmlXTreeObject("treeboxbox_tree", "100%", "97%", 0);
tree.enableTreeLines(true);
tree.enableCheckBoxes(true);
//tree.setSkin('dhx_skyblue');
tree.setImagePath("<%=basePath %>thirtpart/dhtmlx25/imgs/csh_winstyle/");
tree.enableDragAndDrop(0);
tree.enableTreeLines(true);
//tree.setImageArrays("plus", "", "", "", "plus.gif");
//tree.setImageArrays("minus", "", "", "", "minus.gif");
//tree.setStdImages("book.gif", "books_open.gif", "books_close.gif");
//tree.setImageArrays("plus", "", "", "", "", "plus.gif");
//tree.setImageArrays("minus", "", "", "", "", "minus.gif");
//tree.setStdImages("book.gif", "folderOpen.gif", "folderClosed.gif");
 
//tree.setOnOpenHandler(tonopen);
//tree.attachEvent("onOpenEnd", function(nodeId, event) {
//    doLog("An id of open item is " + nodeId);
//});
tree.setOnClickHandler(tonclick);
tree.setOnCheckHandler(toncheck);
tree.attachEvent("onBeforeCheck", function(id,state){
	var userData = tree.getUserData(id,"tagtype"); 
    if("0" == state ){
	    if("" == tagtype){
	    	tagtype = userData;
	    	return true;
	    }else{
	    	if(tagtype != userData){
	    	   alert("检索主题分类共分为四个主题：病名、方剂、证候、中药，同时只能选择一个主题分类！"); 
	    	   return false;
	    	}else{
	    	   return true;
	    	}
	    } 
    } else{
    	return true;
    }
});

//tree.setOnDblClickHandler(tondblclick);

tree.preventIECaching(true);
//tree.enableSmartXMLParsing(true);//false to disable 
tree.enableDistributedParsing(true,20,50);
//tree.enableSmartXMLParsing(true); 

tree.setXMLAutoLoading("<%=basePath %>search/loadnode.do");
// tree.loadXML("<%=basePath %>search/subjecttree.do");
tree.loadXML("<%=basePath %>search/maintree.do");	
	
}
doOnLoad(); 
var divH = window.screen.availHeight*0.73;
document.getElementById("treeboxbox_tree").style.height = divH; 
//alert(document.getElementById("treeboxbox_tree").style.height);
//alert(window.screen.availHeight);
//tree.showItemCheckbox(1, false);
 function resetAll(){
 	clearAllSelectedItem();
 }

	</script>